//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_applyMorphine.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);


	_cond = false;
	_array = items player;
	switch (true) do
	{
		case (BTC_r_med_fa == 0) : {if (_array find "FirstAidKit" != -1) then {_cond = true;};};
		case (BTC_r_med_fa == 1) : {if (_array find "FirstAidKit" != -1 || _array find "Medikit" != -1) then {_cond = true;};};
		case (BTC_r_med_fa == 2) : {if (_array find "Medikit" != -1) then {_cond = true;};};
	};
	BTC_r_action_menu = false;
	if (!isNull BTC_r_unit_dlg && _cond) then
	{
		private ["_unit"];
		_unit = BTC_r_unit_dlg;
		closeDialog 0;
		if (BTC_r_action == 1) then
		{	
			player playMove "AinvPknlMstpSnonWnonDnon_medicUp0";
			//ainvpknlmstpslaywrfldnon_medic self morphine
			//Up AinvPknlMstpSnonWnonDnon_medicUp3
			// morto AinvPknlMstpSnonWnonDnon_medic3
			sleep 5;			
			if (!isNull _unit && format ["%1",player getVariable "BTC_need_revive"] == "0") then
			{
				private ["_state"];
				_state = (_unit getVariable "BTC_r_status");
				_unit setVariable ["BTC_r_status",[(_state select 0),(_state select 1),0,(_state select 3),(_state select 4)],true];
			};
		}
		else
		{
			private ["_pos","_timeout","_unc"];
			hint "Applying Morphine, do not move!";
			_pos = getpos _unit;
			_timeout = time + 6;
			_unc = false;
			while {_pos distance getPos _unit < 1 && time < _timeout && !isNull _unit && player getVariable "BTC_need_revive" == 0 && Alive _unit} do
			{
				if (BTC_r_unc_loop) then {_unc = true;};
				sleep 0.1;
			};
			if (_pos distance getPos _unit < 1 && !isNull _unit && player getVariable "BTC_need_revive" == 0 && Alive _unit && !_unc) then
			{
				private ["_state"];
				_state = (_unit getVariable "BTC_r_status");
				_unit setVariable ["BTC_r_status",[(_state select 0),(_state select 1),0,(_state select 3),(_state select 4)],true];
				hint "Morphine applied!";				
			} else {hint "Morphine could not be applied!";};
		};
		switch (true) do
		{
			case (BTC_r_med_fa == 0) : {player removeItem "FirstAidKit";};
			case (BTC_r_med_fa == 1) : {if (_array find "Medikit" == -1) then {player removeItem "FirstAidKit";};};
		};
	};
	if (!_cond) then {hint "You don't have a first aid kit!";closeDialog 0;};
	BTC_r_action_menu = true;
